package com.duoduo.demo.springboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.duoduo.demo.springboot.dao.HelpCategoryDao;
import com.duoduo.demo.springboot.model.HelpCategory;

@RestController("/api/help")
public class HelpApi {

	@Autowired
	private HelpCategoryDao helpCategoryDao;

	@RequestMapping("/category/all")
	public List<HelpCategory> listAll() {
		return helpCategoryDao.listAll();
	}

	@RequestMapping("/category/root")
	public List<HelpCategory> listRoot() {
		return helpCategoryDao.listByParent(0);
	}

	@RequestMapping("/category/parent/{parentId}")
	public List<HelpCategory> listRoot(@PathVariable Integer parentId) {
		return helpCategoryDao.listByParent(parentId);
	}

	@RequestMapping("/category/{id}")
	public HelpCategory getCategoryById(@PathVariable Integer id) {
		return helpCategoryDao.getById(id);
	}
}
